#pragma once

#include<pthread.h>

//RAII 思想

class Mutex
{
    pthread_mutex_t *_mutex;
public:
    Mutex(pthread_mutex_t *__mutex):_mutex(__mutex)
    {

    }
    ~Mutex()
    {

    }

    void Lock()
    {
        pthread_mutex_lock(_mutex);
    }

    void Unlock()
    {
        pthread_mutex_unlock(_mutex);
    }

};

class LockGuard
{
    Mutex _Mutex;
public:
    LockGuard(pthread_mutex_t* __mutex)
    :_Mutex(__mutex)
    {
        _Mutex.Lock();
    }

    ~LockGuard()
    {
        _Mutex.Unlock();
    }
};
